<template>
  <div v-loading="listLoading">
    <el-tabs type="border-card">
      <el-tab-pane label="佣金比例">
        <commission :permission="permission" :mallConfig="mallConfig" @save="save"></commission>
      </el-tab-pane>
      <el-tab-pane label="首页轮播图">
        <swiper :permission="permission" :tableData="banners" @sort="getData"></swiper>
      </el-tab-pane>
      <el-tab-pane label="购买须知">
        <notice :permission="permission" :mallConfig="mallConfig" @save="save"></notice>
      </el-tab-pane>
      <el-tab-pane label="邮费管理">
        <postage :permission="permission" :mallConfig="mallConfig" @save="save"></postage>
      </el-tab-pane>
      <el-tab-pane label="短信提醒">
        <message :permission="permission" :mallConfig="mallConfig" @save="save"></message>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
  // import swiperSetting form './tabs/swiper.vue'
  import {mallConfig, mallConfigSave} from '@/api/goods'
  import {mall_mallSetting} from '@/utils/permission'
  export default {
    components: {
      commission: require('./tabs/commission.vue').default,
      swiper: require('./tabs/swiper.vue').default,
      postage: require('./tabs/postage.vue').default,
      message: require('./tabs/message.vue').default,
      notice: require('./tabs/notice.vue').default
    },
    data() {
      return {
        listLoading: false,
        permission: 3,
        mallConfig: {
          companyId: null,
          freeShipping: null,
          enableMallSms: -1,
          distL1Ratio: null,
          distL2Ratio: null,
          distL3Ratio: null,
          distAgentRatio: null,
          distPartnerRatio: null,
          distBranchRatio: null,
          mallSmsRecipient: null,
          notice: '',
          isInvoce: -1,
        },
        banners: []
      }
    },
    created() {
      this.getModelPermission()
      this.getData()
    },
    methods: {
      getModelPermission() {
        this.permission = mall_mallSetting()
      },
      getData() {
        if (this.listLoading) {
          return
        }
        this.listLoading = true
        mallConfig().then(res => {
          this.listLoading = false
          this.mallConfig = res.data.data.mallConfig ? res.data.data.mallConfig : this.mallConfig
          this.banners = res.data.data.banners.length > 0 ? res.data.data.banners : this.banners
        }).catch(err => {
          this.listLoading = false
          console.log(err)
        })
      },
      save(msg) {
        if (this.listLoading) {
          return
        }
        this.mallConfig.msg = msg
        var data = {data: this.mallConfig}
        this.listLoading = true
        mallConfigSave(data).then(res => {
          this.listLoading = false
          if (res.data.statusCode == 200) {
            this.mallConfig.companyId = res.data.data
            this.$message({
              type: 'success',
              message: '保存成功！'
            })
          }
        }).catch(err => {
          this.listLoading = false
          console.log(err)
        })
      },
    }
  }
</script>
<style scoped>

</style>
